# encoding=utf-8
import sys
reload(sys)
import os
import datetime,time
sys.setdefaultencoding('utf-8')

def getScreenShot(driver,file_name):
    '''截图函数'''
    img_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) + '//Result//screenshots//'
    dateCurrent = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')  # 现在
    screen_save_path = img_folder + file_name+"_"+dateCurrent + '.png'
    screen_save_path = screen_save_path.replace('//', '\\')
    driver.get_screenshot_as_file(screen_save_path)
    return screen_save_path

#获取当前时间字符串函数
def getCurrentTime():
    dateCurrent=datetime.datetime.now().strftime('%Y%m%d_%H%M%S')  # 现在
    return dateCurrent
#获取当前时间字符串函数
def writeErrorLog(errorMsg):
    errorMsg=getCurrentTime()+'\n'+errorMsg+'\n'
    try:
        f = open("D:/logs/appiumError.txt",'a+')
    except Exception as e:
        print "File is not found."
    f.write(errorMsg)

